/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.core.util;

import org.proteusframework.core.api.model.IDisplayableName;
import org.proteusframework.core.api.model.INamespace;

import java.net.URL;

/**
 * Utility methods for working with {@link org.proteusframework.core.api.model.INamespace} instances.
 *
 * @author Tacoma Four
 */
public final class NameUtil
{
    /**
     * Utility class.
     */
    private NameUtil()
    {

    }

    /**
     * Converts a qualified name into a canonically formatted name using dot-notation, i.e. namespace + "." + id.
     *
     * @param namespace Qualified name to canonically represent
     * @return Canonical representation of the qualified name
     */
    public static String getCanonicalName(INamespace namespace)
    {
        return namespace.getFamily() + "." + namespace.getId();
    }


    /**
     * Creates a displayable name from the given attributes.
     *
     * @param name        Human readable name
     * @param description Human readable description
     * @param glyphURL    URL of an icon used for visual representation
     * @return Displayable name
     */
    public static IDisplayableName createName(final String name,
                                              final String description,
                                              final URL glyphURL)
    {
        return new IDisplayableName()
        {
            @Override
            public String getName()
            {
                return name;
            }

            @Override
            public String getDescription()
            {
                return description;
            }

            @Override
            public URL getGlyphURL()
            {
                return glyphURL;
            }

            @Override
            public String getFamily()
            {
                return null;
            }

            @Override
            public String getId()
            {
                return null;
            }

            @Override
            public String getRefId()
            {
                return null;
            }
        };
    }

    /**
     * Creates a displayable name from a singular name.
     *
     * @param name Name to use in the displayable name
     * @return Displayable name
     */
    public static IDisplayableName createName(final String name)
    {
        return new IDisplayableName()
        {
            @Override
            public String getName()
            {
                return name;
            }

            @Override
            public String getDescription()
            {
                return null;
            }

            @Override
            public URL getGlyphURL()
            {
                return null;
            }

            @Override
            public String getFamily()
            {
                return null;
            }

            @Override
            public String getId()
            {
                return null;
            }

            @Override
            public String getRefId()
            {
                return null;
            }
        };
    }
}
